package appapi.service.impl;

import appapi.Request.ModulelistPageReq;
import appapi.Request.ModulelistReq;
import appapi.dao.ModulelistMapper;
import appapi.entity.auth.ModulelistEntity;
import appapi.service.ModulelistService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 模块信息
 *
 * @author lc
 * @version 1.0
 * @date 2023-05-17 10:08:28
 */
@Service
public class ModulelistServiceImpl  implements ModulelistService {

    @Autowired
    private ModulelistMapper modulelistMapper;

    @Override
    public PageInfo<ModulelistEntity> page(ModulelistPageReq req) {
        if (ObjectUtils.allNotNull(req.getCurrPage(), req.getPageSize())){
            PageHelper.startPage(req.getCurrPage(), req.getPageSize());
        }
        String json = JSON.toJSONString(req);
        ModulelistReq dataReq = JSON.parseObject(json, new TypeReference<ModulelistReq>() {
        });
        List<ModulelistEntity> list = modulelistMapper.list(dataReq);
        PageInfo pageInfo = new PageInfo(list);

        return pageInfo;
    }

    @Override
    public List<ModulelistEntity> list(ModulelistReq modulelistReq) {
        return modulelistMapper.list(modulelistReq);
    }

    @Override
    public ModulelistEntity detail(Long moduId) {
        return modulelistMapper.detail(moduId);
    }

    @Override
    public int count(ModulelistEntity modulelistEntity) {
        return modulelistMapper.count(modulelistEntity);
    }

    @Override
    public int insert(ModulelistEntity modulelistEntity) {
        return modulelistMapper.insertModule(modulelistEntity);
    }

    @Override
    public int update(ModulelistEntity modulelistEntity) {
        return modulelistMapper.updateModule(modulelistEntity);
    }

    @Override
    public int delete(Long moduId) {
        return modulelistMapper.deleteModule(moduId);
    }
}
